package com.example.hydrogengenerator.base

import android.content.pm.PackageInfo
import android.view.Gravity.CENTER
import com.lishuaihua.toast.ToastUtils
import me.hgj.jetpackmvvm.base.BaseApp
import me.jessyan.autosize.AutoSizeConfig


class App : BaseApp() {


    companion object {
        lateinit var instance: App
    }

    override fun onCreate() {
        super.onCreate()
        AutoSizeConfig.getInstance().isCustomFragment = true

        instance = this
        ToastUtils.init(this)
        ToastUtils.setGravity(CENTER, 0, 0)

        CrashHandler.instance.init(this)
//        val channelId = getString(R.string.default_notification_channel_id)
//
//        val notificationManager =
//            getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//            // Create channel to show notifications.
//            val channelName = getString(R.string.default_notification_channel_id)
//            notificationManager.createNotificationChannel(
//                NotificationChannel(
//                    channelId,
//                    channelName,NotificationManager.IMPORTANCE_HIGH
//                )
//            )
//        }

    }

    fun isAvilible(packageName: String): Boolean {
        val packageNames = ArrayList<String>()
        this.packageManager?.getInstalledPackages(0)?.let {
            for (info: PackageInfo in it) {
                packageNames.add(info.packageName)
            }
        }
        return packageNames.contains(packageName)
    }

}
